class ApiError extends Error {}

export default function useApiError() {
  const throwApiError = (msg: string) => {
    throw new ApiError(msg);
  };

  const ifApiError = (e: any, msg: string) => {
    if (e instanceof ApiError) {
      return e.message;
    }
    return msg;
  };

  return { throwApiError, ifApiError };
}
